<?php
session_start();
$begintime = microtime(true);
header("Content-type:text/html;charset=utf-8");
require_once './lib.php';
$mysql = new DBAccess();
/*
 *                                          问题分析
 * 1、如何查找到最新的订单号，以及该订单号对应的彩票类型！
 * 解决方法1：在插入数据的同时将订单号，彩票类型，彩票期号保存到session中，然后通过session传递值！（是否可行，需实践）
 * 解决方法2：定义一个全局数组，在插入数据时将解决方法1中的数据保存到数组中，然后通过全局数组将值进行数据处理
 * 解决方法3：需要用到的数据，N张表中的数据 期号 开奖结果，查表 换算 比对
 *
 */
//            清空中奖状态信息，用于测试！！！！
//
//            $sql="update order_lottery_sub set status=0,is_win=''";
//            $sql1="update order_lottery set status=0";
//            $mysql->query($sql);
//            $mysql->query($sql1);
//            $endtime = microtime(true);
//            $resultime = $endtime - $begintime;
//            echo "页面运行时间：$resultime";
//            exit();

//重庆时时彩结算器
if ($_SESSION['cq_res']) {
    $cq = $_SESSION['cq_res']['hm'];
    $cqs = $_SESSION['cq_res']['hms'];
    $cqqishu = $_SESSION['cq_res']['qishu'];
    $cqqishu = "20180105029";
    $sql = "select * from order_lottery_sub WHERE order_num=ANY (select order_lottery.order_num from order_lottery WHERE lottery_number= $cqqishu) AND status=0";
    //$sql = "select * from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number= 20171228082) AND status=0";
    $res = $mysql->getRows($sql);

     if ($res) {

        $num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $dx = array('大', '小');
        $ds = array('单', '双');
        $zjresultall = array();
        foreach ($res as $k => $v) {
            $order_sub[] = $v['order_sub_num'];
            if ($v['quick_type'] == "第一球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $cq[0]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($cq[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($cq[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第二球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $cq[1]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($cq[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {

                    if ($v['number'] == Ssc_Ds($cq[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第三球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $cq[2]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($cq[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($cq[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第四球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $cq[3]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($cq[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($cq[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第五球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $cq[4]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($cq[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($cq[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "总和龙虎和") {
                if (in_array($v['number'], $cqs['zh'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "前三") {
                if (in_array($v['number'], $cqs['three'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "中三") {
                if (in_array($v['number'], $cqs['three'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "后三") {
                if (in_array($v['number'], $cqs['three'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
         $order_sub = implode(',', $order_sub);
        if ($zjresultall) {
            foreach ($zjresultall as $k => $v) {
                $win = 0.0;
                //更新子表信息
                $set = array('is_win' => 1, 'status' => 1);
                //$sql = "update order_lottery_sub set is_win='1', status='1' where order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0";
                //$mysql->query($sql);
                $mysql->updateRows_me('order_lottery_sub', $set, "order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0");
                $win = (float)$v['win'];
                //更新用户中奖金额，并加入用户余额中
                $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
                $mysql->query($sql_money);

            }

            //$sql = "update order_lottery_sub set ('is_win'=0,'status'=1) WHERE order_num='$v[order_num] And status=0'";
            $set = array('is_win' => 0, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "status=0 AND order_sub_num in ($order_sub)");

            //更新主表信息
            $sql = "update order_lottery set status='1' WHERE status=0 AND lottery_number=$cqqishu";
            $mysql->query($sql);

        }
    } else//如果存在没有下注的订单则直接修改彩票开奖结果的结算状态信息
    {
        echo "没有重庆时时彩订单<br>";
        $sql = "update lottery_result_cq set state='1' WHERE qishu=$cqqishu";
        echo $sql, '<br>';
        $mysql->query($sql);
    }
}
//北京PK10结算器
if ($_SESSION['bjpk_res']) {
    $pk = $_SESSION['bjpk_res']['hm'];
    $pks = $_SESSION['bjpk_res']['hms'];
    $pkqishu = $_SESSION['bjpk_res']['qishu'];
//    var_dump($hms);
    //测试数据
    //$qishu = "661233";
    $sql = "select * from order_lottery_sub WHERE order_num=ANY (select order_lottery.order_num from order_lottery WHERE lottery_number= $pkqishu) AND status=0";
    //$sql = "select * from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number= 20171228082) AND status=0";
    $res = $mysql->getRows($sql);
//    var_dump($res);
    if ($res) {
        $num = array('10', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $dx = array('大', '小');
        $ds = array('单', '双');
        $lh = array('龙', '虎');
        $zjresultall = array();
        foreach ($res as $k => $v) {
            $order_sub[] = $v['order_sub_num'];
            if ($v['quick_type'] == "冠军") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[0]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $lh)) {
                    if ($v['number'] == $pks['lh'][0]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            }

            if ($v['quick_type'] == "亚军") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[1]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $lh)) {
                    if ($v['number'] == $pks['lh'][1]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            }
            if ($v['quick_type'] == "第三名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[2]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $lh)) {
                    if ($v['number'] == $pks['lh'][2]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            }
            if ($v['quick_type'] == "第四名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[3]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $lh)) {
                    if ($v['number'] == $pks['lh'][3]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            }
            if ($v['quick_type'] == "第五名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[4]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $lh)) {
                    if ($v['number'] == $pks['lh'][4]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            }
            if ($v['quick_type'] == "第六名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[5]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[5])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[5])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }
            if ($v['quick_type'] == "第七名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[6]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[6])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[6])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }
            if ($v['quick_type'] == "第八名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[7]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[7])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[7])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }
            if ($v['quick_type'] == "第九名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[8]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[8])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[8])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }
            if ($v['quick_type'] == "第十名") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pk[9]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $dx)) {
                    if ($v['number'] == pk10_Dx($pk[9])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($pk[9])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }
            if ($v['quick_type'] == "冠亚军和") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $pks['zhs']) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
//                    elseif($pks['zhs']==11)
//                    {
//                        $array=
//                    }

                }
                if (in_array($v['number'], $dx)) {
                    if (in_array($v['number'], $pks['zh'])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
                if (in_array($v['number'], $ds)) {
                    if (in_array($v['number'], $pks['zh'])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }

            }

        }
        $order_sub = implode(',', $order_sub);
        if ($zjresultall) {
            foreach ($zjresultall as $k => $v) {
                $win = 0.0;
                //更新子表信息
                // $sql = "update order_lottery_sub set ('is_win'=1,'status'=1) WHERE order_num=$k AND order_sub_num='$v[order_sub_num]'";
                $set = array('is_win' => 1, 'status' => 1);
                $mysql->updateRows_me('order_lottery_sub', $set, "order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0");
                $win = (float)$v['win'];
//                //更新用户中奖金额，并加入用户余额中
                $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
                $mysql->query($sql_money);
//                //$sql = "update order_lottery_sub set ('is_win'=0,'status'=1) WHERE order_num='$v[order_num] And status=0'";
            }
        }
        //更新子表其余信息
        $set = array('is_win' => 0, 'status' => 1);
        $mysql->updateRows_me('order_lottery_sub', $set, "status=0");
        //更新主表信息
        $sql = "update order_lottery set status='1' WHERE status=0";
        $mysql->query($sql);
        //更新彩票开奖结果结算状态信息
        $sql = "update lottery_result_bjpk set state='1' WHERE qishu=$pkqishu AND state=0";
        $mysql->query($sql);
    } else//如果存在没有下注的订单则直接修改彩票开奖结果的结算状态信息
    {
        echo "没有北京PK十订单<br>";
        $sql = "update lottery_result_bjpk set state='1' WHERE qishu=$pkqishu";
        echo $sql, '<br>';
        $mysql->query($sql);
    }
}
//福彩3D结算器
if ($_SESSION['d3_res']) {
    $d3 = $_SESSION['d3_res']['d3'];
    $d3s = $_SESSION['d3_res']['d3s'];
    $fcqishu = $_SESSION['d3_res']['qishu'];
    //测试数据！
    //$fcqishu = "2018010511";

    $sql = "select * from order_lottery_sub WHERE order_num=ANY (select order_lottery.order_num from order_lottery WHERE lottery_number= $fcqishu) AND status=0";
    //$sql = "select * from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number= 20171228082) AND status=0";
    $res = $mysql->getRows($sql);

    if ($res) {
        $num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $dx = array('大', '小');
        $ds = array('单', '双');
        $zjresultall = array();
        foreach ($res as $k => $v) {
            $order_sub[] = $v['order_sub_num'];
            if ($v['quick_type'] == "第一球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $d3[0]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($d3[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($d3[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第二球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $d3[1]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($d3[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($d3[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第三球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $d3[2]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == Ssc_Dx($d3[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($d3[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "总和龙虎和") {
                if (in_array($v['number'], $d3s['zh'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "三连") {
                if (in_array($v['number'], $d3s['sl'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "跨度") {
                if ($v['number'] == $d3s['kd'][0]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        $order_sub = implode(',', $order_sub);
        if ($zjresultall) {
            foreach ($zjresultall as $k => $v) {
                $win = 0.0;
                //更新子表信息
                $set = array('is_win' => 1, 'status' => 1);
                //$sql = "update order_lottery_sub set is_win='1', status='1' where order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0";
                //$mysql->query($sql);
                $mysql->updateRows_me('order_lottery_sub', $set, "order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0");
                $win = (float)$v['win'];
                //更新用户中奖金额，并加入用户余额中
                $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
                echo $sql_mone, '<br>';;
                $mysql->query($sql_money);
            }
            //$sql = "update order_lottery_sub set ('is_win'=0,'status'=1) WHERE order_num='$v[order_num] And status=0'";
            $set = array('is_win' => 0, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "status=0 AND order_sub_num in ($order_sub)");
            //更新主表信息
            $sql = "update order_lottery set status='1' WHERE status=0 AND lottery_number=$fcqishu" ;
            echo $sql, '<br>';
            $mysql->query($sql);

            $sql = "update lottery_result_d3 set state='1' WHERE qishu=$fcqishu";
            echo $sql, '<br>';
            $mysql->query($sql);

        }
    } else//如果存在没有下注的订单则直接修改彩票开奖结果的结算状态信息
    {
        echo '没有福彩3D订单<br>';
        $sql = "update lottery_result_d3 set state='1' WHERE qishu=$fcqishu";
        echo $sql, '<br>';
        $mysql->query($sql);
    }
}
//广东11选5
if ($_SESSION['gd11_res']) {
    $gd11 = $_SESSION['gd11_res']['gd11'];
    $gd11s = $_SESSION['gd11_res']['gd11s'];
    $gd11qishu = $_SESSION['gd11_res']['qishu'];

    //$gd11qishu = "2018010508";
    $sql = "select * from order_lottery_sub WHERE order_num=ANY (select order_lottery.order_num from order_lottery WHERE lottery_number= $gd11qishu) AND status=0";
    $res = $mysql->getRows($sql);
    if ($res) {


        $num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $dx = array('大', '小');
        $ds = array('单', '双');
        $zjresultall = array();
        foreach ($res as $k => $v) {
            $order_sub[] = $v['order_sub_num'];
            if ($v['quick_type'] == "第一球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $gd11[0]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == gd11x5_Dx($gd11[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($gd11[0])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第二球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $gd11[1]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == gd11x5_Dx($gd11[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {

                    if ($v['number'] == Ssc_Ds($gd11[1])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第三球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $gd11[2]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == gd11x5_Dx($gd11[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($gd11[2])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第四球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $gd11[3]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == gd11x5_Dx($gd11[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($gd11[3])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "第五球") {
                if (in_array($v['number'], $num)) {
                    if ($v['number'] == $gd11[4]) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $dx)) {
                    if ($v['number'] == gd11x5_Dx($gd11[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                } elseif (in_array($v['number'], $ds)) {
                    if ($v['number'] == Ssc_Ds($gd11[4])) {
                        $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                        array_push($zjresultall, $array);
                    }
                }
            } elseif ($v['quick_type'] == "总和龙虎和") {
                if (in_array($v['number'], $gd11s['zh'])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "前三") {
                if ($v['number'] == $gd11s['three'][0]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "中三") {
                if ($v['number'] == $gd11s['three'][1]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif ($v['quick_type'] == "后三") {
                if ($v['number'] == $gd11s['three'][2]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        $order_sub = implode(',', $order_sub);
        if ($zjresultall) {
            foreach ($zjresultall as $k => $v) {
                $win = 0.0;
                //更新子表信息
                $set = array('is_win' => 1, 'status' => 1);
                $mysql->updateRows_me('order_lottery_sub', $set, "order_num=$v[order_num] AND order_sub_num=$v[order_sub_num] AND status=0");
                $win = (float)$v['win'];
                //更新用户中奖金额，并加入用户余额中
                $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
                $mysql->query($sql_money);

            }
            //$sql = "update order_lottery_sub set ('is_win'=0,'status'=1) WHERE order_num='$v[order_num] And status=0'";
            $set = array('is_win' => 0, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "status=0 AND order_sub_num in ($order_sub)");

            //更新主表信息
            $sql = "update order_lottery set status='1' WHERE qishu=$gd11qishu";
            $mysql->query($sql);

        }
    } else//如果存在没有下注的订单则直接修改彩票开奖结果的结算状态信息
    {
        echo "没有广东11选5的订单<br>";
        $sql = "update lottery_result_gd11 set state='1' WHERE qishu=$gd11qishu";
        echo $sql, '<br>';
        $mysql->query($sql);
    }
}


//页面运行时
$endtime = microtime(true);
$resultime = $endtime - $begintime;
echo "页面运行时间：$resultime";
